home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gawk
/
gawk215b.zoo
/
gawk.man
< prev
next >
Wrap
Text File
|
1993-06-28
|
43KB
|
1,093 lines
GAWK(1) ST Programmer Manual GAWK(1)
NAME
gawk - pattern scanning and processing language
SYNOPSIS
gawk [ POSIX or GNU style options ] -f program-file [ -- ]
file ...
gawk [ POSIX or GNU style options ] [ -- ] program-text file
...
DESCRIPTION
Gawk is the GNU Project's implementation of the AWK program-
ming language. It conforms to the definition of the
language in the POSIX 1003.2 Command Language And Utilities
Standard. This version in turn is based on the description
in The AWK Programming Language, by Aho, Kernighan, and
Weinberger, with the additional features defined in the Sys-
tem V Release 4 version of UNIX awk. Gawk also provides
some GNU-specific extensions.
The command line consists of options to gawk itself, the AWK
program text (if not supplied via the -f or --file options),
and values to be made available in the ARGC and ARGV pre-
defined AWK variables.
OPTIONS
Gawk options may be either the traditional POSIX one letter
options, or the GNU style long options. POSIX style options
start with a single ``-'', while GNU long options start with
``--''. GNU style long options are provided for both GNU-
specific features and for POSIX mandated features. Other
implementations of the AWK language are likely to only
accept the traditional one letter options.
Following the POSIX standard, gawk-specific options are sup-
plied via arguments to the -W option. Multiple -W options
may be supplied, or multiple arguments may be supplied
together if they are separated by commas, or enclosed in
quotes and separated by white space. Case is ignored in
arguments to the -W option. Each -W option has a
corresponding GNU style long option, as detailed below.
Gawk accepts the following options.
-F fs
--field-separator=fs
Use fs for the input field separator (the value of the
FS predefined variable).
-v var=val
--assign=var=val
Assign the value val, to the variable var, before exe-
cution of the program begins. Such variable values are
available to the BEGIN block of an AWK program.
-f program-file
--file=program-file
Read the AWK program source from the file program-file,
instead of from the first command line argument. Mul-
tiple -f (or --file) options may be used.
-W compat
--compat Run in compatibility mode. In compatibility
mode, gawk behaves identically to UNIX awk; none
of the GNU-specific extensions are recognized.
See GNU EXTENSIONS, below, for more information.
-W copyleft
-W copyright
--copyleft
--copyright Print the short version of the GNU copyright
information message on the error output.
-W help
-W usage
--help
--usage Print a relatively short summary of the avail-
able options on the error output.
-W lint
--lint Provide warnings about constructs that are dubi-
ous or non-portable to other AWK implementa-
tions.
-W posix
--posix This turns on compatibility mode, with the fol-
lowing additional restrictions:
o✓+ \x escape sequences are not recognized.
o✓+ The synonym func for the keyword function is
not recognized.
o✓+ The operators ** and **= cannot be used in
place of ^ and ^=.
-W source=program-text
--source=program-text
Use program-text as AWK program source code.
This option allows the easy intermixing of
library functions (used via the -f and --file
options) with source code entered on the command
line. It is intended primarily for medium to
large size AWK programs used in shell scripts.
The -W source= form of this option uses the rest
of the command line argument for program-text;
no other options to -W will be recognized in the
same argument.
-W version
--version Print version information for this particular
copy of gawk on the error output. This is use-
ful mainly for knowing if the current copy of
gawk on your system is up to date with respect
to whatever the Free Software Foundation is dis-
tributing.
-- Signal the end of options. This is useful to
allow further arguments to the AWK program
itself to start with a ``-''. This is mainly
for consistency with the argument parsing con-
vention used by most other POSIX programs.
Any other options are flagged as illegal, but are otherwise
ignored.
AWK PROGRAM EXECUTION
An AWK program consists of a sequence of pattern-action
statements and optional function definitions.
pattern { action statements }
function name(parameter list) { statements }
Gawk first reads the program source from the program-file(s)
if specified, or from the first non-option argument on the
command line. The -f option may be used multiple times on
the command line. Gawk will read the program text as if all
the program-files had been concatenated together. This is
useful for building libraries of AWK functions, without hav-
ing to include them in each new AWK program that uses them.
To use a library function in a file from a program typed in
on the command line, specify /dev/tty as one of the
program-files, type your program, and end it with a ^D
(control-d).
The environment variable AWKPATH specifies a search path to
use when finding source files named with the -f option. If
this variable does not exist, the default path is
".,c:/lib/awk,c:/gnu/lib/awk". If a file name given
to the -f option contains a ``/'' character, no path search
is performed.
Gawk executes AWK programs in the following order. First,
gawk compiles the program into an internal form. Next, all
variable assignments specified via the -v option are per-
formed. Then, gawk executes the code in the BEGIN block(s)
(if any), and then proceeds to read each file named in the
ARGV array. If there are no files named on the command
line, gawk reads the standard input.
If a filename on the command line has the form var=val it is
treated as a variable assignment. The variable var will be
assigned the value val. (This happens after any BEGIN
block(s) have been run.) Command line variable assignment is
most useful for dynamically assigning values to the vari-
ables AWK uses to control how input is broken into fields
and records. It is also useful for controlling state if mul-
tiple passes are needed over a single data file.
If the value of a particular element of ARGV is empty (""),
gawk skips over it.
For each line in the input, gawk tests to see if it matches
any pattern in the AWK program. For each pattern that the
line matches, the associated action is executed. The pat-
terns are tested in the order they occur in the program.
Finally, after all the input is exhausted, gawk executes the
code in the END block(s) (if any).
VARIABLES AND FIELDS
AWK variables are dynamic; they come into existence when
they are first used. Their values are either floating-point
numbers or strings, or both, depending upon how they are
used. AWK also has one dimension arrays; multiply
dimensioned arrays may be simulated. Several pre-defined
variables are set as a program runs; these will be described
as needed and summarized below.
Fields
As each input line is read, gawk splits the